using UnityEngine;

namespace QFramework.RollABall
{
    public class GameCamera
    {
        private GameObject mCameraObj { get; set; }

        public GameCamera()
        {
            // 默认摄像机的创建
            mCameraObj = Fluent.GameObject()
                .Name("Main Camera")
                .Build();

            Fluent.Camera(mCameraObj)
                .Position(new Vector3(0, 10, -10))
                .EulerAngles(new Vector3(45, 0, 0))
                .Build();
        }


        public void StartFollowPlayer(GameObject playerObj)
        {
            // 计算 摄像机和玩家的偏移值
            var offset = mCameraObj.transform.position - playerObj.transform.position;

            Fluent.MonoBehaviour(mCameraObj)
                .OnLateUpdate(() =>
                {
                    // 每一帧都去设置偏移值，保证 Camera 永远与 Player 的相对位置不变
                    mCameraObj.transform.position = playerObj.transform.position + offset;
                })
                .Build();
        }
    }
}